const htmlWebpackPlugin=require('html-webpack-plugin');
const webpack = require('webpack');
module.exports={
    // entry:['./src/script/main.js','./src/script/a.js'],
    entry:'./src/app.js',
    output:{
        path:__dirname+'/dist',//这里必须填绝对地址，可以通过__dirname来获取当前文件
        filename:'js/[name].bundle.js',
    },
    module: {
        rules: [
          {
               test: /\.js$/, 
               exclude: /node_modules/, 
               loader: "babel-loader" ,
            //    query:{presets:['lastest']
            },
            {
                test:/\.css$/,
                // loader:'style-loader!css-loader!postcss-loader',
                // loaders:[
                //     "style-loader",
                //     "css-loader",
                //     "postcss-loader"
                // ]

                use: [
                    { loader: 'style-loader' },
                    {
                      loader: 'css-loader', options: {
                        sourceMap: true, modules: true,
                        localIdentName: '[local]_[hash:base64:5]'
                      }
                    },
                    {
                        loader: 'postcss-loader',
                        options: {
                          ident: 'postcss',
                          plugins: (loader) => [
                            //require('postcss-import')({ root: loader.resourcePath }),
                            //require('postcss-cssnext')(),
                            require('autoprefixer')(),
                            //require('cssnano')()
                          ]
                        }
                      }
                ]
            },
            {
                test:/\.scss$/,
               loader:'style-loader!css-loader!postcss-loader!sass-loader'
            },
            {
                test:/\.html$/,
                use:[
                    {loader:'html-loader'}
                ]
            },
            {
                test:/\.ejs$/,
                use:[
                    {loader:"ejs-loader"}
                ]
            },
            {
                test:/\.(png|jpg")$/,
                loaders: [
                    'url-loader?limit=2000000&file/[name]-[hash:5].[ext]',
                    'image-webpack-loader'],
                // options: {
                //     name: 'file/[name]-[hash:5].[ext]'
                //   }
            }
            
        ]
    },

    //webpack中怎么使用插件
    //plugins和loader的区别

    plugins: [
        new htmlWebpackPlugin({
            filename:'index.html',//用于指定文件名称
            template: './index.html',
            inject:'body',//指定生成的脚本放在head标签里，还是body标签里
            // minify:{
            //     removeComments:true,//删除注释
            //     collapseWhitespace:true,//删除空格
            // }
            //chunks:['main','a'],//把需要的chunks传入到页面中
            //excludeChunks:['main']//除了main，都出入到页面中
            
        })
       
    ]
}